```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>内存管理：栈、堆与静态区</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        .hero {
            background: linear-gradient(135deg, #6e8efb 0%, #a777e3 100%);
            color: white;
        }
        .card {
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .stack-card {
            border-top: 4px solid #4F46E5;
        }
        .heap-card {
            border-top: 4px solid #10B981;
        }
        .static-card {
            border-top: 4px solid #F59E0B;
        }
        .code-block {
            background-color: #2D3748;
            color: #E2E8F0;
            border-radius: 0.375rem;
            font-family: 'Courier New', Courier, monospace;
        }
        .feature-icon {
            font-size: 1.5rem;
            margin-right: 1rem;
            color: inherit;
        }
        .footer {
            background-color: #1A202C;
            color: #E2E8F0;
        }
        .footer a:hover {
            color: #A0AEC0;
        }
        .characteristic-item {
            position: relative;
            padding-left: 2rem;
        }
        .characteristic-item::before {
            content: "";
            position: absolute;
            left: 0;
            top: 0.6em;
            width: 0.5rem;
            height: 0.5rem;
            border-radius: 50%;
            background-color: currentColor;
        }
        h1, h2, h3 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero py-20 px-4 md:px-0">
        <div class="container mx-auto max-w-4xl text-center">
            <h1 class="text-4xl md:text-5xl font-bold mb-6">探索内存管理的奥秘</h1>
            <p class="text-xl md:text-2xl mb-8 opacity-90">深入理解栈、堆和静态区的核心原理与应用场景</p>
            <div class="inline-flex items-center px-4 py-2 bg-white bg-opacity-20 rounded-full">
                <i class="fas fa-microchip mr-2"></i>
                <span>计算机科学基础</span>
            </div>
        </div>
    </section>

    <!-- Intro Section -->
    <section class="py-16 px-4 md:px-0">
        <div class="container mx-auto max-w-4xl">
            <div class="bg-white rounded-xl shadow-md overflow-hidden p-8">
                <h2 class="text-2xl font-bold mb-6 text-gray-800">内存区域概述</h2>
                <p class="text-gray-700 mb-6">在计算机程序中，内存管理是至关重要的概念。程序运行时，数据被存储在三个主要的内存区域：栈(Stack)、堆(Heap)和静态区(Static Area)。每个区域都有其独特的特点和适用场景。</p>
                
                <div class="mermaid mb-8">
                    graph TD
                    A[程序内存] --> B[栈 Stack]
                    A --> C[堆 Heap]
                    A --> D[静态区 Static Area]
                    B --> E[局部变量]
                    B --> F[函数调用]
                    C --> G[动态分配内存]
                    C --> H[对象实例]
                    D --> I[全局变量]
                    D --> J[静态变量]
                    D --> K[常量]
                </div>
                
                <p class="text-gray-700">理解这些内存区域的差异对于编写高效、可靠的程序至关重要。下面我们将详细探讨每个区域的特点、工作原理和实际应用。</p>
            </div>
        </div>
    </section>

    <!-- Stack Section -->
    <section class="py-16 px-4 md:px-0 bg-gray-50">
        <div class="container mx-auto max-w-4xl">
            <div class="flex items-center mb-10">
                <div class="bg-indigo-100 p-3 rounded-full mr-4">
                    <i class="fas fa-layer-group text-indigo-600 text-2xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">栈(Stack)</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div class="card stack-card bg-white rounded-xl shadow-md overflow-hidden">
                    <div class="p-8">
                        <h3 class="text-xl font-bold mb-4 text-gray-800">核心特点</h3>
                        <ul class="space-y-3">
                            <li class="characteristic-item">自动管理内存分配与释放</li>
                            <li class="characteristic-item">遵循先进后出(LIFO)原则</li>
                            <li class="characteristic-item">访问速度极快</li>
                            <li class="characteristic-item">内存空间有限</li>
                        </ul>
                    </div>
                    <div class="bg-gray-50 px-8 py-6">
                        <h3 class="text-xl font-bold mb-4 text-gray-800">应用场景</h3>
                        <div class="flex items-start mb-3">
                            <i class="fas fa-code-branch feature-icon text-indigo-600"></i>
                            <div>
                                <h4 class="font-semibold">函数调用管理</h4>
                                <p class="text-gray-600 text-sm">存储函数调用信息和返回地址</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <i class="fas fa-memory feature-icon text-indigo-600"></i>
                            <div>
                                <h4 class="font-semibold">局部变量存储</h4>
                                <p class="text-gray-600 text-sm">函数内部定义的变量存储位置</p>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div>
                    <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8">
                        <div class="p-6">
                            <div class="code-block p-4 text-sm overflow-x-auto">
                                <span class="text-purple-400">void</span> <span class="text-blue-400">demoFunction</span>() {<br>
                                &nbsp;&nbsp;&nbsp;&nbsp;<span class="text-purple-400">int</span> localVar = <span class="text-yellow-400">10</span>; <span class="text-gray-500">// 局部变量存储在栈中</span><br>
                                }
                            </div>
                        </div>
                    </div>
                    
                    <div class="bg-white rounded-xl shadow-md overflow-hidden">
                        <div class="p-6">
                            <h3 class="text-lg font-bold mb-4 text-gray-800">栈的工作原理</h3>
                            <div class="mermaid">
                                %%{init: {'theme': 'neutral'}}%%
                                sequenceDiagram
                                    participant 主程序
                                    participant 栈
                                    主程序->>栈: 调用函数A()
                                    栈->>栈: 压入返回地址
                                    栈->>栈: 压入函数A的局部变量
                                    主程序->>栈: 函数A调用函数B()
                                    栈->>栈: 压入返回地址
                                    栈->>栈: 压入函数B的局部变量
                                    栈->>栈: 函数B执行完成，弹出局部变量
                                    栈->>栈: 弹出返回地址
                                    栈->>栈: 函数A执行完成，弹出局部变量
                                    栈->>栈: 弹出返回地址
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Heap Section -->
    <section class="py-16 px-4 md:px-0">
        <div class="container mx-auto max-w-4xl">
            <div class="flex items-center mb-10">
                <div class="bg-green-100 p-3 rounded-full mr-4">
                    <i class="fas fa-database text-green-600 text-2xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">堆(Heap)</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <div class="card heap-card bg-white rounded-xl shadow-md overflow-hidden mb-8">
                        <div class="p-8">
                            <h3 class="text-xl font-bold mb-4 text-gray-800">核心特点</h3>
                            <ul class="space-y-3">
                                <li class="characteristic-item">手动管理内存分配与释放</li>
                                <li class="characteristic-item">动态分配任意大小的内存</li>
                                <li class="characteristic-item">访问速度相对较慢</li>
                                <li class="characteristic-item">内存空间较大</li>
                                <li class="characteristic-item">可能存在内存碎片</li>
                            </ul>
                        </div>
                    </div>
                    
                    <div class="bg-white rounded-xl shadow-md overflow-hidden">
                        <div class="p-6">
                            <h3 class="text-lg font-bold mb-4 text-gray-800">堆的内存分配</h3>
                            <div class="mermaid">
                                graph LR
                                A[程序请求内存] --> B[内存管理器查找空闲块]
                                B --> C{足够大的块?}
                                C -->|是| D[分配内存]
                                C -->|否| E[合并相邻空闲块]
                                E --> C
                                D --> F[更新空闲块列表]
                            </div>
                        </div>
                    </div>
                </div>
                
                <div>
                    <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8">
                        <div class="p-6">
                            <div class="code-block p-4 text-sm overflow-x-auto">
                                <span class="text-purple-400">public class</span> <span class="text-blue-400">Demo</span> {<br>
                                &nbsp;&nbsp;&nbsp;&nbsp;<span class="text-purple-400">public static</span> <span class="text-purple-400">void</span> <span class="text-blue-400">main</span>(String[] args) {<br>
                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="text-purple-400">int</span>[] array = <span class="text-purple-400">new</span> <span class="text-purple-400">int</span>[<span class="text-yellow-400">1000</span>]; <span class="text-gray-500">// 动态分配内存存储数组</span><br>
                                &nbsp;&nbsp;&nbsp;&nbsp;}<br>
                                }
                            </div>
                        </div>
                    </div>
                    
                    <div class="card bg-white rounded-xl shadow-md overflow-hidden">
                        <div class="p-8">
                            <h3 class="text-xl font-bold mb-4 text-gray-800">应用场景</h3>
                            <div class="flex items-start mb-4">
                                <i class="fas fa-boxes feature-icon text-green-600"></i>
                                <div>
                                    <h4 class="font-semibold">动态数据结构</h4>
                                    <p class="text-gray-600">如链表、树、图等数据结构通常在堆中分配</p>
                                </div>
                            </div>
                            <div class="flex items-start mb-4">
                                <i class="fas fa-archive feature-icon text-green-600"></i>
                                <div>
                                    <h4 class="font-semibold">大型数据存储</h4>
                                    <p class="text-gray-600">需要大量内存空间的数组或对象</p>
                                </div>
                            </div>
                            <div class="flex items-start">
                                <i class="fas fa-clock feature-icon text-green-600"></i>
                                <div>
                                    <h4 class="font-semibold">长生命周期对象</h4>
                                    <p class="text-gray-600">需要在多个函数调用间保持的对象</p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Static Area Section -->
    <section class="py-16 px-4 md:px-0 bg-gray-50">
        <div class="container mx-auto max-w-4xl">
            <div class="flex items-center mb-10">
                <div class="bg-yellow-100 p-3 rounded-full mr-4">
                    <i class="fas fa-globe text-yellow-600 text-2xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">静态区(Static Area)</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div class="card static-card bg-white rounded-xl shadow-md overflow-hidden">
                    <div class="p-8">
                        <h3 class="text-xl font-bold mb-4 text-gray-800">核心特点</h3>
                        <ul class="space-y-3">
                            <li class="characteristic-item">程序启动时分配内存</li>
                            <li class="characteristic-item">程序结束时释放内存</li>
                            <li class="characteristic-item">数据共享于所有实例</li>
                            <li class="characteristic-item">生命周期与程序相同</li>
                        </ul>
                    </div>
                    <div class="bg-gray-50 px-8 py-6">
                        <h3 class="text-xl font-bold mb-4 text-gray-800">应用场景</h3>
                        <div class="flex items-start mb-3">
                            <i class="fas fa-project-diagram feature-icon text-yellow-600"></i>
                            <div>
                                <h4 class="font-semibold">全局变量</h4>
                                <p class="text-gray-600 text-sm">程序范围内可访问的变量</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <i class="fas fa-lock feature-icon text-yellow-600"></i>
                            <div>
                                <h4 class="font-semibold">常量数据</h4>
                                <p class="text-gray-600 text-sm">程序运行期间不变的常量</p>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div>
                    <div class="bg-white rounded-xl shadow-md overflow-hidden">
                        <div class="p-6">
                            <div class="code-block p-4 text-sm overflow-x-auto">
                                <span class="text-purple-400">public class</span> <span class="text-blue-400">Demo</span> {<br>
                                &nbsp;&nbsp;&nbsp;&nbsp;<span class="text-purple-400">public static</span> <span class="text-purple-400">int</span> staticVar = <span class="text-yellow-400">42</span>; <span class="text-gray-500">// 静态变量存储在静态区</span><br>
                                &nbsp;&nbsp;&nbsp;&nbsp;<span class="text-purple-400">public static final</span> <span class="text-purple-400">double</span> PI = <span class="text-yellow-400">3.1415926</span>; <span class="text-gray-500">// 常量</span><br>
                                }
                            </div>
                        </div>
                    </div>
                    
                    <div class="bg-white rounded-xl shadow-md overflow-hidden mt-8">
                        <div class="p-6">
                            <h3 class="text-lg font-bold mb-4 text-gray-800">静态区内存布局</h3>
                            <div class="mermaid">
                                graph TB
                                subgraph 静态区
                                    A[初始化数据]
                                    B[未初始化数据]
                                    C[只读数据]
                                    D[静态变量]
                                    E[全局变量]
                                    F[常量]
                                end
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Comparison Section -->
    <section class="py-16 px-4 md:px-0">
        <div class="container mx-auto max-w-4xl">
            <h2 class="text-3xl font-bold text-center mb-12 text-gray-800">内存区域对比</h2>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden">
                <div class="overflow-x-auto">
                    <table class="min-w-full divide-y divide-gray-200">
                        <thead class="bg-gray-50">
                            <tr>
                                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">特性</th>
                                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-indigo-500 uppercase tracking-wider">栈(Stack)</th>
                                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-green-500 uppercase tracking-wider">堆(Heap)</th>
                                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-yellow-500 uppercase tracking-wider">静态区(Static Area)</th>
                            </tr>
                        </thead>
                        <tbody class="bg-white divide-y divide-gray-200">
                            <tr>
                                <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">内存管理</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">自动</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">手动/GC</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">程序生命周期</td>
                            </tr>
                            <tr>
                                <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">访问速度</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">最快</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">较慢</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">快</td>
                            </tr>
                            <tr>
                                <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">大小限制</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">较小(默认~1MB)</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">较大(取决于系统)</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">固定</td>
                            </tr>
                            <tr>
                                <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">主要用途</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">局部变量、函数调用</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">动态分配对象</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">全局/静态变量、常量</td>
                            </tr>
                            <tr>
                                <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">线程安全</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">线程私有</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">线程共享</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">线程共享</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </section>

    <!-- Footer -->
    <footer class="footer py-10">
        <div class="container mx-auto max-w-4xl px-4 md:px-0">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-4 md:mb-0">
                    <h3 class="text-lg font-semibold">技术小馆</h3>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="text-blue-300 hover:text-blue-200 transition-colors">
                        <i class="fas fa-external-link-alt mr-2"></i>
                        http://www.yuque.com/jtostring
                    </a>
                </div>
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: false,
                htmlLabels: true,
                curve: 'basis'
            },
            sequence: {
                diagramMarginX: 50,
                diagramMarginY: 10,
                boxTextMargin: 5,
                noteMargin: 10,
                messageMargin: 35,
                mirrorActors: true
            }
        });
    </script>
</body>
</html>
```